package com.example.disconf.demo.service.callbacks;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;

import com.baidu.disconf.client.usertools.DisconfDataGetter;
import org.springframework.stereotype.Service;

import com.baidu.disconf.client.common.update.IDisconfUpdatePipeline;

/**
 * Created by knightliao on 16/3/22.
 */
@Service
public class UpdatePipelineCallback implements IDisconfUpdatePipeline {
    private boolean canReloadLocaly(){
        boolean flag=false;
        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            flag = DisconfDataGetter.getByFile("prepublish.properties").containsKey(ip);
            System.out.println(String.format("本地ip=%s, 是否可以更新配置=%s",ip,String.valueOf(flag)));
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return flag;
    }

    public boolean canReloadLocalData(String s) {
        return canReloadLocaly();
    }

    public void reloadDisconfFile(String key, String filePath) throws Exception {
        System.out.println("reloadDisconfFile()"+key);
    }

    public void reloadDisconfItem(String key, Object content) throws Exception {
        System.out.println("reloadDisconfItem()"+key);
    }
}
